﻿package mortal.game.view.guildNew.shop
{
    import mortal.common.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.view.guildNew.*;
    import mortal.game.view.guildNew.data.*;
    import mortal.mvc.interfaces.*;

    public class GuildNewShopPorcessor extends Object
    {
        private var _view:IView;

        public function GuildNewShopPorcessor()
        {
            this.initServer();
            return;
        }// end function

        public function initView(param1:IView) : void
        {
            this._view = param1;
            return;
        }// end function

        public function initServer() : void
        {
            EventUtil.addSelfEvent(EventName.GuildShopGetItem, this.guildShopGetItem, true);
            return;
        }// end function

        public function onViewShow() : void
        {
            this.addEvs(true);
            return;
        }// end function

        public function onViewHide() : void
        {
            this.addEvs(false);
            return;
        }// end function

        private function addEvs(param1:Boolean) : void
        {
            EventUtil.addSelfEvent(GuildNewLocalEvent.GuildNewShopBuy, this.onshopBuy, param1);
            EventUtil.addNetEvent(ServerCommand.GuildShopGetItem, this.updateShopItems, param1);
            EventUtil.addNetEvent(ServerCommand.GUILD_INFO_UPDATE, this.updateGuildInfo, param1);
            return;
        }// end function

        private function guildShopGetItem(event:DataEvent) : void
        {
            GameProxy.guild.getGuildShopItems();
            return;
        }// end function

        private function onshopBuy(event:DataEvent) : void
        {
            var _loc_2:* = event.data;
            GameProxy.guild.buyGuildShopItem(_loc_2.itemCode, _loc_2.num);
            return;
        }// end function

        private function updateShopItems(param1:Object) : void
        {
            if (this._view == null)
            {
                return;
            }
            if ((this._view as GuildNewModule).curPanel == null)
            {
                return;
            }
            var _loc_2:* = (this._view as GuildNewModule).curPanel as GuildNewShopPanel;
            if (_loc_2)
            {
                _loc_2.update();
            }
            return;
        }// end function

        private function updateGuildInfo(param1:Object) : void
        {
            if (this._view == null)
            {
                return;
            }
            if ((this._view as GuildNewModule).curPanel == null)
            {
                return;
            }
            var _loc_2:* = (this._view as GuildNewModule).curPanel as GuildNewShopPanel;
            if (_loc_2)
            {
                _loc_2.updateContribution();
            }
            return;
        }// end function

    }
}
